// 双重循环，暴力求解；
package LC0121;

class Solution1 {
    public static void main(String[] args) {
        Solution1 test = new Solution1();
        int[] prices = {1, 2, 7, 8, 5, 2, 3, 1, 4};
        System.out.println(test.maxProfit(prices));
    }

    public int maxProfit(int[] prices) {
        int maxProfit = 0;

        for (int i = 0; i < prices.length - 1; i++) {
            for (int j = i + 1; j < prices.length; j++) {
                int tempProfit = prices[j] - prices[i];

                if(prices[j] <= prices[j-1]){
                    continue;
                }
                if (tempProfit > maxProfit){
                    maxProfit = tempProfit;
                }
            }
        }

        return maxProfit;
    }
}
